package com.jhx.video.videomanager

import android.os.Bundle
import cn.jzvd.JZVideoPlayer
import com.jhx.common.framework.QuickBaseActivity
import com.jhx.common.model.Event
import com.jhx.common.model.Video
import com.jhx.video.R
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe

/**
 * 视频管理
 *
 * @author Jack 2018-03-12 10:50
 */
class VideoManagerActivity : QuickBaseActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_home)
        push(VideoManagerFragment::class.java)
        setTitle("短视频管理")
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this)
        }
    }

    override fun containerId(): Int {
        return R.id.view_container
    }

    override fun onBackPressed() {
        if (JZVideoPlayer.backPress()) {
            return
        }
        super.onBackPressed()
    }

    @Subscribe
    fun onEvent(event: Event?) {
        if(event != null && event.code == Video.CODE_POST_SUCCESS) {
            finish()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this)
        }
    }
}